function logins() {
    if(null == document.getElementById("phone").value || '' == document.getElementById("phone").value) {
        mui.toast("请输入您的手机号码");
        return;
    }
    if(null == document.getElementById("code").value || '' == document.getElementById("code").value) {
        mui.toast("请输入您的验证码");
        return;
    }
    var phone = $("#phone").val();
    var code = $("#code").val();
    
    localStorage.setItem("LoginData",null)
    localStorage.setItem("key",null)
    localStorage.setItem('phone', JSON.stringify(phone));
    //--------------------
    showDialog();
    //------------------------
    //document.getElementById("div1").innerHTML="<img src='../c81a939801f73ea7105321fa75b96c30.jpg' class='img'>";
    $.ajax({
           type: "POST",
           url: url_prefix + "user/login_code",
           dataType: 'JSON',
           data: {
           request:JSON.stringify({
                                  "mobile": phone,
                                  "code": code,
                                  "companyCode": companyCode
                                  })
           },
           success: function(data) {
           dismissDialog();
           if(data.code == '200') {
           localStorage.removeItem('LoginData');
           localStorage.removeItem('projectData');
           localStorage.removeItem('index');
           localStorage.removeItem('projectname');
           localStorage.setItem('LoginData', JSON.stringify(data.result.user));
           localStorage.setItem('key',data.result.token);
           localStorage.setItem("loginMobile",phone);
           passtoken(data.result.token);
           window.location.href = "home.html";
           
           } else {
           mui.toast(data.message);
           }
           },
           error: function(XMLHttpRequest, textStatus, errorThrown) {
           
           // if(textStatus=='timeout'){
           dismissDialog();
           mui.toast("连接服务器失败,请稍后重试``````");
           //  }
           }
           });
}


function loginPsd() {
    if(null == document.getElementById("name").value || '' == document.getElementById("name").value) {
        mui.toast("请输入您的账号");
        return;
    }
    if(null == document.getElementById("password").value || '' == document.getElementById("password").value) {
        mui.toast("请输入您的密码");
        return;
    }
    var name = $("#name").val();
    var psd = $("#password").val();
    
    localStorage.setItem("LoginData",null)
    localStorage.setItem("key",null)
    showDialog();
    $.ajax({
           type: "POST",
           url: url_prefix + "user/login_account",
           dataType: 'JSON',
           data: {
           request:JSON.stringify({
                                  "name": name,
                                  "password": psd,
                                  "companyCode": companyCode
                                  })
           },
           success: function(data) {
           dismissDialog();
           if(data.code == '200') {
           // localStorage.setItem(data.result.token);
           localStorage.removeItem('LoginData');
           localStorage.removeItem('projectData');
           localStorage.removeItem('index');
           localStorage.removeItem('projectname');
           localStorage.setItem("loginAccount",name);
           localStorage.setItem('LoginData', JSON.stringify(data.result.user));
           localStorage.setItem('key',data.result.token);
           passtoken(data.result.token);
           window.location.href = "home.html";
           } else {
           mui.toast(data.message);
           }
           },
           error: function(XMLHttpRequest, textStatus, errorThrown) {
           
           // if(textStatus=='timeout'){
           dismissDialog();
           mui.toast("连接服务器失败,请稍后重试``````");
           //  }
           }
           });
}


// 获取验证码（从接口请求）
function getcode() {
    if(null == document.getElementById("phone").value || '' == document.getElementById("phone").value) {
        mui.toast("请输入您的手机号码");
        return;
    }
    var phone = $("#phone").val();
    
    var me = verifyMobile(phone)
    
    if(me){
        $.ajax({
               type: "POST",
               url: url_prefix + "send_code",
               dataType: 'JSON',
               data: {
               request: JSON.stringify({
                                       mobile: phone
                                       })
               },
               success: function(data) {
               if(data.code!='200'){
               mui.toast(data.message)
               }else{
               settime();
               }
               
               }
               });
    }else{
        mui.toast('请输入3-16位手机号')
    }
}

var countdown = 60;

function settime() {
    if(countdown == 0) {
        var val = document.getElementById('messgecode');
        val.removeAttribute("disabled");
        document.getElementById('messgecode').innerHTML = "获取验证码";
        //          val.value="获取验证码";
        countdown = 60;
    } else {
        var val = document.getElementById('messgecode');
        val.setAttribute("disabled", true);
        document.getElementById('messgecode').innerHTML = "重新发送(" + countdown + ")";
        //          val.value="重新发送(" + countdown + ")";
        countdown--;
        setTimeout(function() {
                   settime();
                   }, 1000)
    }
}

// 重置密码
function resetpassword(){
    if(null == document.getElementById("mobile").value || '' == document.getElementById("mobile").value) {
        mui.toast("请输入您的手机号码");
        return;
    }
    if(null == document.getElementById("account").value || '' == document.getElementById("account").value) {
        mui.toast("请输入您的账号");
        return;
    }
    if(null == document.getElementById("code").value || '' == document.getElementById("code").value) {
        mui.toast("请输入您的验证码");
        return;
    }
    
    var phone = $("#mobile").val();
    var account = $("#account").val();
    var code = $("#code").val();
    //--------------------
    showDialog();
    //------------------------
    //document.getElementById("div1").innerHTML="<img src='../c81a939801f73ea7105321fa75b96c30.jpg' class='img'>";
    $.ajax({
           type: "POST",
           url: url_prefix + "user/edit/resetUserPassword",
           dataType: 'JSON',
           data: {
           request:JSON.stringify({
                                  "mobile": phone,
                                  "code": code,
                                  "account": account
                                  })
           },
           success: function(data) {
           dismissDialog();
           if(data.code == '200') {
           window.location.href = "login.html";
           } else {
           mui.toast(data.message);
           }
           mui.toast(data.message);
           },
           error: function(XMLHttpRequest, textStatus, errorThrown) {
           
           // if(textStatus=='timeout'){
           dismissDialog();
           mui.toast("连接服务器失败,请稍后重试``````");
           //  }
           }
           });
}
// 重置密码获取验证码
function getcodereset(){
    if(null == document.getElementById("account").value || '' == document.getElementById("account").value) {
        mui.toast("请输入您的账号");
        return;
    }
    if(null == document.getElementById("mobile").value || '' == document.getElementById("mobile").value) {
        mui.toast("请输入您的手机号码");
        return;
    }
    var phone = $("#mobile").val();
    var account = $("#account").val();
    var me = verifyMobile(phone)
    if(me){
        $.ajax({
               type: "POST",
               url: url_prefix + "user/edit/send_resetCode",
               dataType: 'JSON',
               data: {
               request: JSON.stringify({
                                       mobile: phone,
                                       account:account
                                       })
               },
               success: function(data) {
               if(data.code!='200'){
               mui.toast(data.message)
               }else{
               settime();
               }
               
               }
               });
    }else{
        mui.toast('请输入3-16位手机号')
    }
}

